import lombok.extern.slf4j.Slf4j;

/**
 * @author xhw
 */
@Slf4j
public class 斐波那契数列 {

    public static void main(String[] args) {
        int n = 10;
        int[] fib2 = new int[n + 1];
        int result = fib(n, fib2);
        log.warn("斐波那契数列的第 {} 项是：{}", n, result);
    }

    private static int fib(int n, int[] s) {
        //使用日志通过占位符打印递归调用
        log.info("开始计算第{}次", n);
        if (n < 2) {
            return n;
        }
        int[] fib2 = new int[n + 1];
        fib2[0] = 0;
        fib2[1] = 1;
        for (int i = 2; i <= n; i++) {
            fib2[i] = fib2[i - 1] + fib2[i - 2];
        }
        log.info("第{}次计算结束", n);
        return fib2[n];
    }
}
